//
//  HomeTabBarReactor.swift
//  WanAndroidLearn
//
//  Created by TRS-Mobile on 2023/11/6.
//

import Foundation
import ReactorKit

class HomeTabBarReactor: Reactor {
    enum Action {
        case refresh
    }
    
    enum Mutation {
        case allItems([HomeTabBarItem])
    }
    
    struct State {
        var tabBarItems: [HomeTabBarItem] = []
    }
    
    var initialState: State = State()
    
    func reactor(for tabBarItem: HomeTabBarItem) -> any Reactor {
        switch tabBarItem {
        case .home:
            return HomeReactor()
        case .login:
            return LoginReactor()
        }
    }
    
    func mutate(action: Action) -> Observable<Mutation> {
        switch action {
        case .refresh:
            return .just(.allItems([.home, .login]))
        }
    }
    
    func reduce(state: State, mutation: Mutation) -> State {
        var state = state
        switch mutation {
        case .allItems(let array):
            state.tabBarItems = array
        }
        return state
    }
}
